import { computed } from 'vue'
import type { CapsuleItem, CapsuleConfig } from './index.d'

export function useCapsule(items: CapsuleItem[], cfg: CapsuleConfig) {
  const values = computed(() => items.map(i => i.value))
  const max    = computed(() => Math.max(...values.value, 1))
  const rates  = computed(() => values.value.map(v => v / max.value))

  const ruler = computed(() => {
    const step = max.value / 5
    return Array.from(new Set(
      Array.from({ length: 6 }, (_, i) => Math.ceil(i * step))
    ))
  })

  return { rates, values, ruler, cfg }
}